PowerTCP Telnet for .NET CF
Read(Byte[],Int32,Int32) Method
See Also  Example Send comments on this topic.
Dart.Common Namespace > TcpBase Class > Read Method : Read(Byte[],Int32,Int32) Method




buffer
The byte array used to store the received data.
offset
The position in the buffer to store the data.
size
The number of bytes to receive.
Receives data from the remote host.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Read( _
   ByVal buffer() As Byte, _
   ByVal offset As Integer, _
   ByVal size As Integer _
) As Data
Visual Basic (Usage)Copy Code
Dim instance As TcpBase
Dim buffer() As Byte
Dim offset As Integer
Dim size As Integer
Dim value As Data
 
value = instance.Read(buffer, offset, size)
C# 
public Data Read( 
   byte[] buffer,
   int offset,
   int size
)
Managed Extensions for C++ 
public: Data* Read( 
   byte[]* buffer,
   int offset,
   int size
) 
C++/CLI 
public:
Data^ Read( 
   array<byte>^ buffer,
   int offset,
   int size
) 

Parameters

buffer
The byte array used to store the received data.
offset
The position in the buffer to store the data.
size
The number of bytes to receive.

Return Value

A Data object encapsulating the received data.

Example

This example demonstrates execution of a looping Read on a worker thread, and marshaling the data back to the UI. This specific example uses the Telnet component, but the code is the same for any component that derives from TcpBase.
C#Copy Code
//Receive data on a separate thread
telnet1.Start(receiveData, null);

private void receiveData(Telnet telnet, object notUsed)
{
	//Receive data when it is sent by the remote host
	byte[] buffer = new byte[1024];
	while (telnet.State != Dart.Common.ConnectionState.Closed)
		telnet.Marshal(telnet.Read(buffer, 0, 1024), null);
}
    
private void telnet1_Data(object sender, DataEventArgs e)
{
	//Whenever data is received, display it
	textDisplay.Text + e.Data.ToString();
}
Visual BasicCopy Code
'Receive data on a separate thread
telnet.Start(AddressOf receiveData, Nothing)
	
Private Sub receiveData(ByVal telnet As Telnet, ByVal notUsed As Object)
	'Receive data when it is sent by the remote host
	Dim buffer() As Byte = New Byte(1023){}
	Do While telnet.State <> ConnectionState.Closed
		telnet.Marshal(telnet.Read(buffer, 0, 1024), Nothing)
	Loop
End Sub
	
Private Sub telnet1_Data(ByVal sender As Object, ByVal e As DataEventArgs) Handles telnet1.Read
	'Whenever data is received, display it
	textDisplay.Text = e.Data.ToString()
End Sub

Remarks

This method will read as much data as is available, up to the number of bytes specified by the size parameter.

This method will block until data is available or the ReceiveTimeout property has expired.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.